#/bin/bash

init(){
    [ $1 ] && sleep $1

    # 类似给 shell加一个锁(避免脚本多次执行)
    [ "${MY_LOCK}" != "$0"  ] && exec env MY_LOCK="$0" flock -xn "$0" "$0" "$@" 
    
    # 关闭蜂鸣器
    xset -b

    # 将当前目录设置为 scriptPATH
    scriptPATH=$(cd $(dirname $0);pwd)
    
    # 设置自动锁屏(依赖 xautolock 包)
    xautolock -time 10 -locker slock &
    
    # 检测是否禁用触摸板
    /bin/bash $scriptPATH/synapticsMonitor.sh &
}

settings(){
    [ $1 ] && sleep $1

    # status bar
    #/bin/bash $scriptPATH/status-bar.sh &
    #/bin/bash /home/admin/App/cc_dwm/statusbar/statusbar.sh &
    /bin/bash /opt/software/scripts/statusbar2d/statusbar.sh &

    #picom
    while pgrep -u $UID -x picom >/dev/null; do sleep 1; done
    picom --config ~/.config/picom/picom.conf -b

    #wallpaper
    /bin/bash $scriptPATH/wallpaper-autochange.sh &

    #fcitx5
    while pgrep -u $UID -x fcitx5 >/dev/null; do sleep 1; done
    fcitx5 -d

    # redshift (自动调节色域)(护眼软件)
    while pgrep -u $UID -x redshift >/dev/null; do sleep 1; done
    redshift -c ~/.config/redshift.conf &

    # 火焰截图
    while pgrep -u $UID -x flameshot >/dev/null; do sleep 1; done
    flameshot &
}

init 1           # 初始化设置
settings 1       # 启动后台程序
